package com.concerneyes.health.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.concerneyes.R;
import com.concerneyes.health.model.HealthDataModel;

import java.util.ArrayList;
import java.util.List;

import util.Util;

/**
 * Created by Administrator on 2017/6/29 0029.
 */

public class HisCarsAdapter extends BaseAdapter {
    private Context context;
    private List<HealthDataModel> model;

    public HisCarsAdapter(Context context) {
        this.context = context;
        model = new ArrayList<>();
    }

    public void addData(List<HealthDataModel> model) {
        if (model.size()>0){
            this.model.addAll(model);
        }
        notifyDataSetChanged();
    }

    @Override
    public int getCount() {
        return model.size();
    }

    @Override
    public HealthDataModel getItem(int position) {
        return model.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder holder = null;
        if (convertView == null) {
            holder = new ViewHolder();
            convertView = LayoutInflater.from(context).inflate(R.layout.item_his_card, null);
            holder.mTvMeTitle = (TextView) convertView.findViewById(R.id.tv_me_title);
            holder.mTvDataCome = (TextView) convertView.findViewById(R.id.tv_data_come);
            holder.mRlItem = (RelativeLayout) convertView.findViewById(R.id.rl_item);
            convertView.setTag(holder);
        } else {
            holder = (ViewHolder) convertView.getTag();
        }
        holder.mTvMeTitle.setText(Util.changeStringDataStyle(model.get(position).getDataTime()));
        holder.mTvDataCome.setText(model.get(position).getFrom());
        return convertView;
    }

    static class ViewHolder {
        TextView mTvMeTitle;
        TextView mTvDataCome;
        RelativeLayout mRlItem;
    }
}
